package com.softeem.arr;

import java.util.ArrayList;

public class Arr_03 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<Student>();
        //元素添加
        list.add(new Student(1,"张三",18,"计算机"));//0
        list.add(new Student(2,"李四",19,"美容美发"));//1
        list.add(new Student(3,"王五",20,"挖掘机"));//2
        list.add(new Student(4,"赵六",21,"DJ"));//3
        list.add(new Student(5,"孙七",22,"厨师(川菜)"));//4

        //遍历集合
        //list.size():获取到集合的长度
        for(int i = 0; i < list.size(); i++){
            //list.get(下标):获取到集合中的元素
            Student stu = list.get(i);
            System.out.println(stu);//默认调用对象的toString方法
        }

        System.out.println("----------------------------");
        //找到名字叫王五的学生然后将其专业改为太极拳
        for(int i = 0; i < list.size(); i++){
            if("王五".equals(list.get(i).getName())){
                list.get(i).setMajor("太极拳");
            }
        }
        System.out.println(list);

        //查找19 ~ 21岁之间的学生并且将其删除
        for(int i = 0; i < list.size(); i++){
            if(list.get(i).getAge() >= 19 && list.get(i).getAge() <= 21){
                list.remove(i);
                i--;
            }
        }
        System.out.println(list);

        //1 2 3 4 5 6 7 8 9 10 11 12 13             13    0 - 12
        //2 3 4 5 6 7 8 9 10 11 12 13

    }
}
